|
|
|
|
|
|
|
LISTING 7.2. MENUSELECT.TXTBY USING THE COLLECTION ARRAY FOR THE MENU OPTIONS, ALL CODE IS KEPT WITHIN A SINGLE EVENT ROUTINE. |
|
|
|
 |
|
|
|
|
1: Private Sub mnuArray_Click(Index As Integer)
2: Select Case Index
3: Case 1 'File, New
4: 'ToDo: Add File New code.
5: MsgBox Add File New code.
6: Case 2 'File, Open
7: 'ToDo: Add File Open code.
8: MsgBox Add File Open code.
9: End Select
10: End Sub. |
|
|
|
|
|
|
|
|
Which one you choose is entirely up to you; however, this example will use the Select Case method of handling menu events. After you have designed the menu and entered it into the menu editor for the application, you should place a MSGBOX statement for each option's Click event so that when testing the prototype, you will know whether the selection process really works, as shown in the following code:. |
|
|
|
|
|
|
|
|
MSGBOX Place Menu Option & <Option> & Code Here. |
|
|
|
|
|
|
|
|
This MSGBOX also serves as a reminder to you if you forget the code for any particular menu option as you are coding the application. After you have completed the menus, you should run the application and click each of the menu options to ensure that you did not miss one. |
|
|
|
|
|
|
|
|
Besides the main form, you might want to add menu options to the child forms. However, as discussed earlier in the book, you do not really want to add menu options to the child forms if they share several of the same options as the main menu. What you should do is add the extra menu selections to the main menu and make them visible only when needed. |
|
|
|
|
|
|
|
|
This brings you to the topic of which menu options are available when. If you choose the Add New Entry menu option, you can disable it so that the user cannot select it again until the entry process is completed. You do this in the menu click routine with the following code: |
|
|
|
|
|
|
|
|
MnuFileNew.Enabled = False |
|
|
|
|
|
|
|
|
This statement will gray out the menu option instead of hiding it. This is a visual cue that is used to tell the user that this option is not currently available. Then when the Entry form is unloaded, the statement setting this property to True is placed in the form's UNLOAD event. This type of process enables you to turn on and off any menu options that do not make sense to have available at a given moment. |
|
|
|
|
|